package jp.veeva.jtsyka.service;

import java.util.ArrayList;
import java.util.List;

import jp.veeva.jtsyka.mappers.CustomerMapper;
import jp.veeva.jtsyka.model.Customer;
import jp.veeva.jtsyka.model.CustomerKey;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service("CustomerService")
public class CustomerServiceImpl implements CustomerService {

    static final Logger LOG = LoggerFactory.getLogger(CustomerServiceImpl.class);

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void insertCustomer(Customer customer) {
        // TODO Auto-generated method stub

    }

    @Override
    public void deletCustomer(Customer customer) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean getCustomerByCustomer(Customer customer) {
        // TODO Auto-generated method stub
        return false;
    }

    /*
     * (non-Javadoc)
     * @see
     * jp.veeva.jtsyka.service.CustomerService#listCustomer(jp.veeva.jtsyka.
     * model.Customer)
     */
    @Transactional
    public List<Customer> listCustomer(CustomerKey customerKey) {
        List<Customer> list = new ArrayList<Customer>();
        try {
            if (null != customerKey.getTradeStartDay()) {
                
                list.addAll(customerMapper.selectByKey(customerKey));
            }
            LOG.debug("取得した会社情報：" + list);
        } catch (Exception ex) {
            // trigger rollback programmatically
            LOG.error("error発生：" + ex.toString());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return list;
    }

    /*
     * (non-Javadoc)
     * @see jp.veeva.jtsyka.service.CustomerService#getWhsList(jp.veeva.jtsyka.model.CustomerRel)
     */
    @Transactional
    public List<String> getWhsList(CustomerKey customerKey) {
        List<String> list = new ArrayList<String>();
        try {
            if (null != customerKey.getTradeStartDay()) {
                
                list.addAll(customerMapper.selectWhsList(customerKey));
            }
            LOG.debug("取得した会社情報：" + list);
        } catch (Exception ex) {
            // trigger rollback programmatically
            LOG.error("error発生：" + ex.toString());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return list;
    }
}
